package demo.DataStrucAndAlgo.Easy_pritice;

import java.util.Arrays;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/17-08-17-15:54
 * @Description：demo.DataStrucAndAlgo.Easy_pritice
 */
public class MidNum {
    public static void main(String[] args) {

        int[] num1 = {1,2,3,4};
        int[] num2 = {1,4,5,6,7};
        //Arrays.sort(num1);

    }
    public String longestPalindrome(String s) {
        char[] a = s.toCharArray();
        int len = 0;
        int index = 0;
        int max = 1;
        for (int i = 0; i < a.length; i++) {
            for(int j = a.length-1; j > i;j--){
                int temp1 = i,temp2 = j;
                while(a[temp1] == a[temp2] && temp1 <= temp2){
                    temp1++;
                    temp2--;
                }
                if(temp1 >= temp2){
                    len = j-i+1;
                }
                if(max < len){
                    index = i;
                    max = len;
                }
            }
        }
        return s.substring(index,index + max);
    }
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        double mid = 0;
        if(nums1.length==0 && nums2.length==0){
            return 0;
        }
        int[] result = new int[nums1.length+nums2.length];
        System.arraycopy(nums1,0,result,0,nums1.length);
        System.arraycopy(nums2,0,result,nums1.length,nums2.length);
        Arrays.sort(result);
        if(result.length % 2 == 0){
            mid =  (result[result.length/2] + result[result.length/2-1])/2.0;
        }else{
            mid = result[result.length/2];
        }
        return mid;
    }
}
